﻿using System;
using System.IO;
using System.Net;
using System.Xml;
using System.Xml.Linq;

namespace HttpCrawler.Engine
{
    public class XmlHttpCrawlerContent : HttpCrawlerContent
    {
        public XmlHttpCrawlerContent(Uri requestUrl, Uri referrerUrl, HttpWebResponse webResponse)
            : base(requestUrl, referrerUrl, webResponse)
        {
            Xml = XDocument.Load(Stream);
        }

        public override void Save(Stream stream)
        {
            using (var xmlWriter = XmlWriter.Create(stream))
            {
                Xml.WriteTo(xmlWriter);
            }
        }

        public XDocument Xml
        {
            get;
            protected set;
        }

        public override string Text
        {
            get
            {
                return Xml.ToString();
            }
        }
    }
}
